package com.arpa.wms.handler;

import com.arpa.wms.domain.dto.AuthDto;
import com.arpa.wms.domain.entity.Shop;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 上下文 用一个map来维护，获取所有有HandlerType的类
 * @author leo
 */
@Service
public class RefreshTokenHandlerContext {

    @Autowired
    private final Map<String, AbstractTokenManagerHandler> handlerMap = new ConcurrentHashMap<>();

    public RefreshTokenHandlerContext(Map<String, AbstractTokenManagerHandler> handlerMap) {
        handlerMap.forEach(this.handlerMap::put);
    }

    public void getRefreshTokenHandler(Shop shop){
        handlerMap.get(shop.getShopType()).refreshToken(shop);
    }
    public void getTokenHandler(AuthDto dto){
        handlerMap.get(dto.getShopType()).getToken(dto);
    }

}
